{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "194ed88e",
   "metadata": {},
   "source": [
    "# Introduction to ArcGIS Hub - Premium features\n",
    "\n",
    "ArcGIS Hub Premium enables organizations, like local non-profits, governments, or schools, to share a project or update with their community by starting an initiative or creating a site and organizing content and teams to share web maps, apps, datasets, and more with the public. Hub Premium also supports creating and sharing events related to your initiative using hub's built-in events management system. Click [here](https://www.esri.com/en-us/arcgis/products/arcgis-hub/resources) to learn more about ArcGIS Hub.\n",
    "\n",
    "In this notebook, we will explore the Hub Premium capabilities of __Initiatives__ and __Events__."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e1bcd86c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from arcgis.gis import GIS"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3578e60b",
   "metadata": {},
   "source": [
    "First, we will sign in to an organization with Hub Premium enabled to demonstrate these workflows. \n",
    "\n",
    "> _Note:_ In order to replicate these workflows for yourself, you may have to verify the features available to you, per your ArcGIS Hub licensing. \n",
    "\n",
    "You may also want to look at these examples for site and page creation and cloning using [ArcGIS Basic](../hub-basic-guide) and site and page layout and theme editing using [Enterprise Sites](../enterprise-sites-guide) to see the other ways of working with your Hub using the ArcGIS API for Python. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c1423e98",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter password: ········\n"
     ]
    }
   ],
   "source": [
    "gis = GIS(profile=\"your_online_hub_premium_profile\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "723532c9",
   "metadata": {},
   "source": [
    "Next, we will initialize a [Hub](/python/api-reference/arcgis.apps.hub.html#hub) object to create an initiative with this Hub Premium Web GIS."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "97c78b32",
   "metadata": {},
   "outputs": [],
   "source": [
    "hub_premium = gis.hub"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6d98bf5d",
   "metadata": {},
   "source": [
    "### Adding new Initiatives\n",
    "\n",
    "An Initiative supports policy or activity oriented goals through workflows, tools and team collaboration. Initiatives manage the team, events, content, and experiences involved in achieving a shared goal.\n",
    "\n",
    "You can add a new initiative with the following commands:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "28ae447b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n",
       "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n",
       "                       <a href='https://dcdev.maps.arcgis.com/home/item.html?id=5ffb2e4d30244d78b19eda1c84d63db1' target='_blank'>\n",
       "                        <img src='http://static.arcgis.com/images/desktopapp.png' class=\"itemThumbnail\">\n",
       "                       </a>\n",
       "                    </div>\n",
       "\n",
       "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n",
       "                        <a href='https://dcdev.maps.arcgis.com/home/item.html?id=5ffb2e4d30244d78b19eda1c84d63db1' target='_blank'><b>Initiative with Python</b>\n",
       "                        </a>\n",
       "                        <br/>Create your own initiative by combining existing applications with a custom site. Use this initiative to form teams around a problem and invite your community to participate.<img src='https://dcdev.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/layers16.png' style=\"vertical-align:middle;\">Hub Initiative by creator1\n",
       "                        <br/>Last Modified: December 12, 2022\n",
       "                        <br/>0 comments, 0 views\n",
       "                    </div>\n",
       "                </div>\n",
       "                "
      ],
      "text/plain": [
       "<Item title:\"Initiative with Python\" type:Hub Initiative owner:creator1>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "initiative1 = hub_premium.initiatives.add(title='Initiative with Python')\n",
    "initiative1.item"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "166f9ac9",
   "metadata": {},
   "source": [
    "A Hub Initiative comes with an Initiative item and a Site item. You also get a Content Team group created to manage the content in your initiative's content library and a Followers Team group that maintains a list of the followers of the initiative. Users with Administrative privileges that create an initiative will also have a Core Team group created as part of the initiative, to allow collaboration among members of that team.\n",
    "\n",
    "To access the site of an initiative, you can fetch the site using the `site_id` property of the initiative."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5fcb627a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n",
       "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n",
       "                       <a href='https://dcdev.maps.arcgis.com/home/item.html?id=dc6c5ddd9963464a9b5ab438ead11156' target='_blank'>\n",
       "                        <img src='http://static.arcgis.com/images/desktopapp.png' class=\"itemThumbnail\">\n",
       "                       </a>\n",
       "                    </div>\n",
       "\n",
       "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n",
       "                        <a href='https://dcdev.maps.arcgis.com/home/item.html?id=dc6c5ddd9963464a9b5ab438ead11156' target='_blank'><b>Initiative with Python</b>\n",
       "                        </a>\n",
       "                        <br/><img src='https://dcdev.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/layers16.png' style=\"vertical-align:middle;\">Hub Site Application by creator1\n",
       "                        <br/>Last Modified: December 12, 2022\n",
       "                        <br/>0 comments, 0 views\n",
       "                    </div>\n",
       "                </div>\n",
       "                "
      ],
      "text/plain": [
       "<Item title:\"Initiative with Python\" type:Hub Site Application owner:creator1>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "site1 = hub_premium.sites.get(initiative1.site_id)\n",
    "site1.item"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bf74dcdf",
   "metadata": {},
   "source": [
    "### Searching for and Fetching initiatives\n",
    "\n",
    "Initiatives that have been previously created can be searched for across your Hub."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "87ab129d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<Initiative title:\"Vision Zero - v180628\" owner:publisher2>,\n",
       " <Initiative title:\"Vision Zero Maine Demo\" owner:content_mgr1>,\n",
       " <Initiative title:\"Vision Zero Tags\" owner:hub_user4>,\n",
       " <Initiative title:\"vision-zero-1\" owner:publisher2>,\n",
       " <Initiative title:\"Vision Zero - courtney\" owner:content_mgr3>]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "initiatives = hub_premium.initiatives.search(title='Vision Zero', tags='Hub')\n",
    "initiatives[:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "722236bd",
   "metadata": {},
   "source": [
    "You can also fetch a particular initiative using its item id."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b942fb0b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Initiative title:\"Walkability Assessment \" owner:creator1>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "initiative2 = hub_premium.initiatives.get('07fad5be49da45bea02c8f5b0876be24')\n",
    "initiative2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1e374ac",
   "metadata": {},
   "source": [
    "### Update an Initiative\n",
    "\n",
    "You can update certain initiative properties using the [`update()`](/python/api-reference/arcgis.apps.hub.html#arcgis.apps.hub.initiatives.Initiative.update) method on the [Initiative](/python/api-reference/arcgis.apps.hub.html#arcgis.apps.hub.html#initiative) object. The list of properties that can be updated using this method can be found [here](/python/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.update).\n",
    "\n",
    "We will first print the current snippet of the initiative we created, update it and verify the update."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e985d147",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Create your own initiative by combining existing applications with a custom site. Use this initiative to form teams around a problem and invite your community to participate.'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "initiative1.snippet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e24a96b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "initiative1.update(initiative_properties={\"snippet\":\"Test change of snippet\"})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "24da6316",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Test change of snippet'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "initiative1.snippet"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "170d00cc",
   "metadata": {},
   "source": [
    "### Delete an Initiative\n",
    "\n",
    "Deleting an initiative deletes the initiative and site items, as well as the groups created as part of the initiative creation process."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "bd874dce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "initiative1.delete()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91c48972",
   "metadata": {},
   "source": [
    "### Searching for Events\n",
    "\n",
    "ArcGIS Hub supports engagement through in-person and virtual events. Events are meetings for people to support an Initiative and are scheduled by an organizer and have many attendees. An Event will have an associated Group that will allow you to include content for preparation as well as gather and archive content during the event for later retrieval or analysis."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5d36606",
   "metadata": {},
   "source": [
    ">_Note:_ The pattern to add, search, get, update and delete Events is identical to that of Initiatives."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ac795ff7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<Event title:\"Test\" venue:White House>,\n",
       " <Event title:\"Bicycle Lanes in Ward 8\" venue:Anacostia Neighborhood Library>,\n",
       " <Event title:\"Neighborhood Kickoff\" venue:>,\n",
       " <Event title:\"Hub Onsite Kickoff\" venue:>,\n",
       " <Event title:\"Hub Home brainstorming\" venue:>]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "all_events = hub_premium.events.search()\n",
    "all_events[:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "19174aee",
   "metadata": {},
   "source": [
    "You can also filter your events search by `initiative_id`, `title`, `venue`, and `organizer_name` as demonstrated below:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "017ca836",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<Event title:\"Bicycle Lanes in Ward 8\" venue:Anacostia Neighborhood Library>]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "events_title = hub_premium.events.search(title='Ward')\n",
    "events_title[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "70d45343",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<Event title:\"Test\" venue:White House>,\n",
       " <Event title:\"Test Attendance\" venue:The White House>,\n",
       " <Event title:\"Test 2\" venue:The White House>,\n",
       " <Event title:\"Katie Test\" venue:The White House>,\n",
       " <Event title:\"Let's talk Python\" venue:The White House>]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "events_organizer = hub_premium.events.search(venue='White House')\n",
    "events_organizer[:5]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
